<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .empty {
            height: 1000px;
        }

        .box {
            width: 200px;
            height: 100px;
            background-color: lightseagreen;
        }
    </style>
</head>

<body>
    <div class="empty"></div>
    <div class="box"></div>
    <div class="empty"></div>
    <script>
        // 获取元素对象
        var box=document.querySelector('.box')
        var wHeight=window.innerHeight
        window.onscroll=function(){
            // 动态获取元素所在矩形区域的信息你
            var rect=box.getBoundingClientRect()
            // 1-元素顶部距离浏览器顶部距离<浏览器视口高度
            // 2-元素底部距离浏览器视口顶部距离>0
            if(rect.top<wHeight && rect.bottom>0){
                console.log('元素进入浏览器可视区域');
            }
        }
    </script>
</body>

</html>